function saveForm() {
    debugger
    const self = this;
    let descriptionText = self.$$("textarea_gkcto5").$$getValue();
    if (descriptionText == null || descriptionText == "") {
        self.$message.warning("请填写注销原因！");
        return true;
    }

    const formPartEle = self.$$("form_part_gaaht8");
    const formRenderEle = formPartEle.$$getRenderElement();
    let documentNo = formRenderEle.getDocumentNo();
    // 发起审核，新增发起审核记录
    // 通过申请部门查询复审人员或部门
    let applyUnitId = self.$$("number_input_7y33xw").cValue;
    reviewDepartmentRegion(applyUnitId).then(res => {
        reviewDepartment(res.regionId).then(res => {
            // 获取审核部门
            let approvalDateValue = res;
            let applyDate = {
                confiscatedCardId: documentNo,
                unitId: '',
                unitName: '',
                humanId: '',
                humanName: '',
                approvalStateCode: "1",
                approvalType: "3",
                opinion: descriptionText,
                stageId: "1",
                stageName: "罚没证注销申请"
            }
            // 新增发起审核记录
            insertLawConfiscatedCardApprovalInfo(applyDate).then(res => {
                let approvalDate = {
                    confiscatedCardId: documentNo,
                    unitId: approvalDateValue.unit_id,
                    unitName: approvalDateValue.unit_name,
                    humanId: approvalDateValue.human_id,
                    humanName: approvalDateValue.human_name,
                    approvalStateCode: "0",
                    approvalType: "3",
                    opinion: "",
                    stageId: "2",
                    stageName: "复审"
                }
                setTimeout(() => {
                    insertLawConfiscatedCardApprovalInfo(approvalDate).then(res => {
                        // 修改当前证件状态为注销
                        api.EXEC_FORMULA("UPDATE('ds_tbl:t_78e3820cec034204b3ec0f507253f5de', QUERY_EQ('id','" + documentNo + "'), '', ['card_state_code', '" + 4 + "','STATE_CODE','2'])").then((res) => {
                            self.$message.success("注销申请成功！");
                            let pageRenderElement = self.$$root().$parent.$parent.$parent;
                            pageRenderElement.goHistory(-1);
                        })

                    });
                }, 100);


            })
        })
    })
}

/**
 * 获取复审部门或人员
 * @param unitId
 * @returns {Promise<unknown>}
 */
function reviewDepartment(regionId) {
    const params = [{
        name: "regionId",
        valueContent: regionId
    }];
    return new Promise(function (resolve, reject) {
        api.DATA_SOURCE_EXECUTE("ds_mod:e75f43e9-228e-46c1-99c9-0740397728ff", "ddcat", params, [], "").then(res => {
            resolve(res.result);
        })
    });
}


/**
 * 获取部门所属区划
 * @param unitId
 * @returns {Promise<unknown>}
 */
function reviewDepartmentRegion(unitId) {
    const params = [{
        name: "unitUid",
        valueContent: unitId
    }];
    return new Promise(function (resolve, reject) {
        api.DATA_SOURCE_EXECUTE("ds_mod:0c9ab6a6-a391-4022-bdb2-7eefd7d222a7", "ddcat", params, [], "").then(res => {
            resolve(res.result[0]);
        })
    });
}

/**
 *  id 表标识
 *  confiscated_card_id 罚没证id
 *  unit_id 审批部门id',
 *  unit_name  审批部门名称',
 *  human_id 审批人员id',
 *  human_name  审批人员名称',
 *  approval_state_code  审批状态 0待审核 1 通过 2 不通过',
 *  opinion  '审批意见',
 *  approval_time   '审批时间',
 *  approval_type 申请类型 1 申请 2 变更 3 注销',
 * @param approvalData
 * @returns {Promise<never>|Promise<unknown>}
 */
function insertLawConfiscatedCardApprovalInfo(approvalData) {

    const insertLawConfiscatedCardApprovalInfoSql = [
        ['confiscated_card_id', approvalData.confiscatedCardId],
        ['unit_id', "'" + approvalData.unitId + "'"],
        ['unit_name', "'" + approvalData.unitName + "'"],
        ['human_id', "'" + approvalData.humanId + "'"],
        ['human_name', "'" + approvalData.humanName + "'"],
        ['approval_state_code', "'" + approvalData.approvalStateCode + "'"],
        ['opinion', "'" + approvalData.opinion + "'"],
        ['approval_type', "'" + approvalData.approvalType + "'"],
        ['STAGE_ID', "'" + approvalData.stageId + "'"],
        ['STAGE_NAME', "'" + approvalData.stageName + "'"],
        ['approval_time', 'NOW()']
    ];

    let law_confiscated_card_approval_info = 'ds_tbl:t_d6d40a9fbcac40568e164e9976b35459';

    // 构建参数化INSERT语句
    const formattedFields = insertLawConfiscatedCardApprovalInfoSql.map(function (field) {
        return "'" + field[0] + "'," + field[1];
    });

    const insertSql = "INSERT('" + law_confiscated_card_approval_info + "', [" + formattedFields.join(',') + "])";
    console.log("准备执行的SQL语句:", insertSql);

    return new Promise(function (resolve, reject) {
        api.EXEC_FORMULA(insertSql)
            .then(function (res) {
                console.log("数据插入成功");
                resolve(res);
            })
            .catch(function (err) {
                console.error("数据插入失败:", err);
                reject(new Error(`审批记录插入失败: ${err.message}`));
            });
    });
}
